import {
  Entity,
  Column,
  PrimaryColumn,
  JoinColumn,
  OneToMany,
  ManyToOne,
  ManyToMany
} from 'typeorm'
import { User, Comment } from './index'

@Entity()
export class Post {
  @PrimaryColumn({ unique: true })
  id: string

  @Column({ default: '' })
  title: string

  @Column({ default: '' })
  description: string

  @Column({ default: '' })
  content: string

  /** 最后一次编辑时间 */
  @Column({ default: '' })
  time: string

  /** 创建时间 */
  @Column({ default: '' })
  creationTime: string

  /** 作者 */
  @ManyToOne(() => User, (item) => item.id)
  @JoinColumn()
  user: User

  /** 评论 */
  @OneToMany(() => Comment, (item) => item.post)
  @JoinColumn()
  comments: Comment[]

  /** 点赞 */
  @ManyToMany(() => User, (item) => item.like)
  @JoinColumn()
  like: User[]

  /** 收藏 */
  @ManyToMany(() => User, (item) => item.collection)
  @JoinColumn()
  collection: User[]
}
